package com.cskaoyan.wordmemorize.auth;

import cn.dev33.satoken.stp.StpInterface;
import com.cskaoyan.wordmemorize.dto.app.UserDTO;
import com.cskaoyan.wordmemorize.service.EmployeeService;
import com.cskaoyan.wordmemorize.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

@Component
public class StpInterfaceImpl implements StpInterface {


    @Autowired
    EmployeeService employeeService;
    @Resource
    UserService userService;
    /*
         只需要自己实现这个方法即可
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        Long userId = Long.parseLong(loginId.toString());
//        if (userId != null){
//            return Arrays.asList("super-admin");
//        }
        if("admin".equals(loginType)){
            // 返回后台用户所拥有的权限别名集合
            Set<String> permissionAlias = employeeService.getPermissionAlias(userId);
            return new ArrayList<>(permissionAlias);
        }else if ("user".equals(loginType)){
            //返回用户的特权码集合
            return userService.getUserInfo(userId).getPrivilegeCodes();
        }
        return null;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}
